/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InitTabDialoguer.java
 *
 * Created on Mar 24, 2009, 6:08:50 PM
 */

package client;

/**
 *
 * @author scriptoff
 */
public class InitTabDialoguer extends javax.swing.JPanel {


    private String pseudo ;
    private Client cl ;
    private Menu_ImSSL_GUI gui ;

    /** Creates new form InitTabDialoguer */
    public InitTabDialoguer(String pseudo, Client client, Menu_ImSSL_GUI gui) {
        this.pseudo = pseudo ;
        this.cl = client ;
        this.gui = gui ;
        initComponents();
    }

    void nouveauMessage( String pseudoEnvoyeur ,   String message) {
        String text = jTextArea1.getText();
        jTextArea1.setText(text+pseudoEnvoyeur+'>'+message+"\n");
    }

   

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jTextField1 = new javax.swing.JTextField();
        bouton_envoyer = new javax.swing.JButton();
        bouton_deconnecter = new javax.swing.JButton();

        setPreferredSize(new java.awt.Dimension(1212, 656));

        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jTextField1KeyPressed(evt);
            }
        });

        bouton_envoyer.setText("Envoyer");
        bouton_envoyer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bouton_envoyerActionPerformed(evt);
            }
        });

        bouton_deconnecter.setIcon(new javax.swing.ImageIcon(getClass().getResource("/client/icons/quitter.png"))); // NOI18N
        bouton_deconnecter.setText("Quitter");
        bouton_deconnecter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bouton_deconnecterActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1188, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 925, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bouton_envoyer, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(bouton_deconnecter, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 581, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(bouton_envoyer)
                        .addComponent(bouton_deconnecter)))
                .addContainerGap(30, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void bouton_envoyerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bouton_envoyerActionPerformed
        String msg =  jTextField1.getText();
        jTextField1.setText("");
        if ( msg == null )
            return ;
        else{
            cl.envoyerMessageUtilisateur(pseudo, msg);
        }
    }//GEN-LAST:event_bouton_envoyerActionPerformed

    private void jTextField1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyPressed
        if (evt.getKeyCode() == evt.VK_ENTER)
            bouton_envoyerActionPerformed(null);
    }//GEN-LAST:event_jTextField1KeyPressed

    private void bouton_deconnecterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bouton_deconnecterActionPerformed
        gui.supprimerDialogue(pseudo);
}//GEN-LAST:event_bouton_deconnecterActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bouton_deconnecter;
    private javax.swing.JButton bouton_envoyer;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables

}
